package leetcode1;

import java.util.*;

public class test2 {
    public List<List<String>> groupAnagrams(String[] strs) {
         Map<String,List<String>> map = new HashMap<String,List<String>>();
         for(String str:strs){
             char[] c = str.toCharArray();
             Arrays.sort(c);
             String key = String.valueOf(c);
             List<String> list = map.getOrDefault(key,new ArrayList<String>());
             list.add(str);
             map.put(key,list);
         }
//         for(Map.Entry<String,List<String>> entry: map.entrySet()){
//             System.out.println(entry.getKey() + " " + entry.getValue());
//         }
//         for(String key : map.keySet()){
//             System.out.println(key + " " + map.get(key));
//         }
//        Iterator<String> iterator = map.keySet().iterator();
//         while (iterator.hasNext()){
//             String key = iterator.next();
//             System.out.println(key + " " + map.get(key));
//         }
//        Iterator<Map.Entry<String,List<String>>> iterator = map.entrySet().iterator();
//         while (iterator.hasNext()){
//             Map.Entry<String,List<String>> entry = iterator.next();
//             System.out.println(entry.getKey() + " " +  entry.getValue());
//         }
         return new ArrayList<List<String>>(map.values());
    }
}
